package com.wash.shoes.entity;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wash.shoes.common.enums.WriteOffStatusEnum;
import com.wash.shoes.util.CovertXcxStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author ljg
 * @since 2024-09-07
 */
@ApiModel(value = "洗护订单")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("os_order")
public class OrderPo extends Model<OrderPo> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "订单的id")
    @TableId
    private String id;
    /**
     * 品牌id
     */
    @TableField("brand_id")
    private String brandId;

    @ApiModelProperty(value = "店铺的id")
    private String shopId;

    @ApiModelProperty(value = "邀请人的ID/WX小程序存在")
    private String inviteCusId;

    @ApiModelProperty(value = "清洗门店")
    private String washShop;
    // 增加清洗工厂字段 add by jjz 20250818 begin
    @TableField("wash_factory")
    private String washFactory;

    // 清洗的工厂id
    @TableField("wash_factory_id")
    private String factoryId;
    // 增加清洗工厂字段 add by jjz 20250818 begin
    @ApiModelProperty(value = "客户的id")
    private String customId;
    @ApiModelProperty(value = "客户名称")
    @TableField(exist = false)
    private String customName;
    @ApiModelProperty(value = "商品的id")
    private String goodsId;

    @ApiModelProperty(value = "客户的电话")
    private String customPhone;

    @ApiModelProperty(value = "抖音预约单号码")
    private String dyBookId;

    @ApiModelProperty(value = "抖音的预约结果的code")
    private String dyBookCode;

    // 订单号时间+店铺的code+自增的5位数
    @ApiModelProperty(value = "订单号")
    private String orderNo;

    @ApiModelProperty(value = "订单来源 1pc 2美团 3抖音 4小程序")
    private String comeFrom;

    @ApiModelProperty(value = "鞋子数量")
    private Integer shoeNum;

    @ApiModelProperty(value = "总价 = 订单金额 - 优惠价格")
    private Double totalPrice;

    @ApiModelProperty(value = "订单金额")
    private Double orderPrice;

    @ApiModelProperty(value = "折扣")
    private Double discountRatio;
    // -1 待支付
    // 0已取消
    // 1取鞋中
    // 2待入库 进店洗已经生成订单，此时详情页应该上传鞋子图片后为清洗中
    // 3清洗中 此时修改鞋子状态为完成，所有完成则待出库
    // 4待出库 修改订单状态为出库
    // 5送鞋中 物流信息
    // 6已完成 done

    // 最终结论:待付款、服务中、已完成、已取消、待评价(这几个用图标)
    // 待取件、送洗中、清洗中、送回中、派送中(服务中的过程，拆分成这几个，用进度条)
    @ApiModelProperty(value = "订单状态")
    private Integer status;

    @ApiModelProperty(value = "是否完成分账")
    private Integer shareAccounts;

    @ApiModelProperty(value = "抖音核销完成时间")
    private Date dyVerificationTime;

    @ApiModelProperty(value = "抖音是否已核销")
    private String writeStatus;

    @ApiModelProperty(value = "推送到自动化工厂")
    private Integer pushAutoFactory;


    // 见 com.wash.shoes.util.CovertXcxStatus 备注
    @ApiModelProperty(value = "订单状态")
    private Integer xcxStatus;
    @ApiModelProperty(value = "需要洗几天")
    private Integer washDays;
    @ApiModelProperty(value = "取鞋日期")
    private String shoeCollectionDate;
    /**
     * 见 FulFillEnum
     */
    @ApiModelProperty(value = "履约状态")
    private String fulfillStatus;
    @ApiModelProperty(value = "客户备注")
    private String customerRemark;
    @ApiModelProperty(value = "入库人")
    private String checkInPerson;
    @ApiModelProperty(value = "入库日期")
    private Date checkInTime;
    @ApiModelProperty(value = "出库人")
    private String checkOutPerson;
    @ApiModelProperty(value = "出库日期")
    private Date checkOutTime;
    @ApiModelProperty(value = "预约日期")
    private String mtBeginTime;
    @ApiModelProperty(value = "店铺备注")
    private String shopRemark;
    @ApiModelProperty(value = "下单时间")
    private String orderTime;
    @ApiModelProperty(value = "mt订单号")
    private String mtOrderId;
    @ApiModelProperty(value = "mt统一订单ID（对外透出的订单号）")
    private String mtUniOrderId;
    @ApiModelProperty(value = "券码信息")
    private String mtSerialNumbers;
    @ApiModelProperty(value = "结算状态 ")
    private String settlementStatus;
    @ApiModelProperty(value = "结算金额")
    private Double settlementPrice;
    @ApiModelProperty(value = "结算时间")
    private Date settlementTime;
    @ApiModelProperty(value = "配件的图片")
    private String fittingImg;
    @ApiModelProperty(value = "备注")
    private String remark;
    @ApiModelProperty(value = "运输的Json信息")
    private String transJson;
    @ApiModelProperty(value = "商品的图片")
    private String shopGoodsUrl;
    @ApiModelProperty(value = "微信支付订单号 说明：原支付交易对应的微信订单号")
    private String wxTransactionId;
    @ApiModelProperty(value = "商户订单号 说明：原支付交易对应的商户订单号")
    private String wxOutTradeNo;
    @ApiModelProperty(value = "商户退款单号")
    private String wxOutRefundNo;
    @ApiModelProperty(value = "扩展字段")
    private String extendInfo;
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建者")
    private String createBy;
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "更新者")
    private String updateBy;
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;
    @TableField(exist = false)
    @ApiModelProperty(value = "订单是取鞋/送鞋")
    private String type;
    /**
     * 核销状态
     */
    @TableField("write_status")
    private WriteOffStatusEnum writeOffStatus;


    /**
     * 自营 1 自营 0 非自营
     */
    @TableField(exist = false)
    private Integer selfOperated;
    /**
     * 质检时间
     */
    @TableField("qualityinsp_time")
    private LocalDateTime qualityInspTime;
    /**
     * 清洗完成时间
     */
    @TableField("completion_time")
    private LocalDateTime completionTime;

    @TableField("accepted")
    @ApiModelProperty(value = "抖音是否接单 1已接单 0 未接单")
    private Boolean accepted;

    public void setStatus(Integer status) {
        this.status = status;
        // 小程序的状态
        xcxStatus = CovertXcxStatus.xcxStatus(status);
    }

    /**
     * 是否是老预约单,老的需要取order 上的bookid,新的取ordergood上面的bookid
     *
     * @return 如果返回true  就取ordergood 表上面的dybookid，否则就取order表上面的dybookid
     */
    public boolean isNewBook() {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date2 = simpleDateFormat.parse("2025-10-22 23:28:00");//系统上线时间
            return createTime.after(date2);
        } catch (Exception e) {
        }
        return false;
    }

    public static void main(String[] args) throws ParseException {
        DateTime dateTime = DateUtil.parse("2025-10-22 23:18:00", "yyyy-MM-dd HH:mm:ss");
//        DateFormatUtils.parse("2025-10-22 23:18:00", "yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = simpleDateFormat.parse("2025-10-22 23:38:00");//订单创建时间
        Date date2 = simpleDateFormat.parse("2025-10-22 23:28:00");//上线时间

        Date date = new Date();
        System.out.println(date1.after(date2));
    }
}
